<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('设置责任民警')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="user-form">
                <div class="select-list">
                    <ul>
                        <li>
                            用户名称：<input type="text" name="username"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "system/user";
    var userList = "";
    $(function () {
        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            onLoadSuccess: onLoadSuccess,
            columns: [{
                radio: true
            },
                {
                    field: 'id',
                    title: '用户ID',
                    visible: false
                },
				{
					field: 'username',
					title: '姓名'
				},
				{
					field: 'deptId_dictText',
					title: '部门'
				},
				{
					field: 'phone',
					title: '联系电话'
				}
                ]
        };
        $.table.init(options);
    });

    /* 添加用户-选择用户-提交 */
    function submitHandler() {
        var rows = $.table.selectFirstColumns();
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.close();
        // 父页面的变量
        userList.forEach(value => {
            if (value.id === rows.join()) {
                parent.$('input[name="policeName"]').val(value.username);
                parent.$('input[name="policeId"]').val(value.id);
            }
        })
    }

    function onLoadSuccess(res) {
        userList = res.rows;
    }
</script>
</body>
</html>
